package com.atguigu.day20.notify03.n1;

public class Bar {
    //记录菜的数量
    static int count;


    //吧台最多可以放的菜品数量
    public static final Integer Max_COUNT = 10;
    //吧台最少放置的菜品数量
    public static final Integer Min_COUNT = 0;

    //厨师线程
    public static synchronized void make() {
        //厨师判断菜的数量 >= 10 等待
        while (count >= Bar.Max_COUNT) {
            try {
                Bar.class.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        //做菜
        count++;

        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        //展示
        System.out.println(Thread.currentThread().getName() + " 做了一道菜,吧台上有[" + count + "]道菜");
        //执行等待的
        Bar.class.notifyAll();
    }

    //服务员
    public static synchronized void take() {
        while (count<=Bar.Min_COUNT){
            try {
                Bar.class.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        //上菜
        count--;
        //展示
        System.out.println(Thread.currentThread().getName() + " 上了一道菜,吧台上还有[" + count + "]道菜");
        Bar.class.notifyAll();
    }

}
